package com.seleniti.enpareja.controller.model.integration.database.domain;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.jdo.annotations.Column;
import javax.jdo.annotations.Element;
import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.Order;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.annotations.Unique;
import javax.jdo.annotations.Version;
import javax.jdo.annotations.VersionStrategy;
import javax.validation.constraints.NotNull;

import com.google.appengine.datanucleus.annotations.Unowned;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
@Version(column = "version", strategy = VersionStrategy.VERSION_NUMBER, extensions = { @Extension(vendorName = "datanucleus", key = "field-name", value = "version") })
public class User {
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
	private String userId;

	@Column(allowsNull = "false")
	@NotNull
	@Unique
	private String userEmail;

	@Column(allowsNull = "false")
	@NotNull
	private String nickName;

	@Column(allowsNull = "true")
	private Gender gender;

	@Column(allowsNull = "true")
	private String password;

	@Column(allowsNull = "true")
	@Unowned
	private User couple;

	@Column(allowsNull = "true")
	private CoupleType coupleType;

	@Column(allowsNull = "true")
	private boolean fakeUser;

	@Persistent(mappedBy = "to")
	@Order(extensions = @Extension(vendorName = "datanucleus", key = "list-ordering", value = "status asc"))
	@Element(dependent = "true")
	private List<CoupleRequest> requestsToYou = new ArrayList<CoupleRequest>(0);

	@Persistent(mappedBy = "user")
	@Element(dependent = "true")
	private Set<Notification> notifications = new HashSet<Notification>(0);

	@Persistent(defaultFetchGroup = "true")
	private Settings settings;

	@Column(allowsNull = "true")
	private Set<String> gcmRegisterId = new HashSet<String>(0);

	@Column
	private Date lastAccess;

	protected long version;

	public String getUserEmail() {
		return userEmail;
	}

	public void setUserEmail(String userEmail) {
		this.userEmail = userEmail;
	}

	public String getNickName() {
		return nickName;
	}

	public void setNickName(String nickName) {
		this.nickName = nickName;
	}

	public Gender getGender() {
		return gender;
	}

	public void setGender(Gender gender) {
		this.gender = gender;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public User getCouple() {
		return couple;
	}

	public void setCouple(User couple) {
		this.couple = couple;
	}

	@Override
	public String toString() {
		return "User [userEmail=" + userEmail + ", nickName=" + nickName + ", gender=" + gender + ", requestsToYou="
				+ (requestsToYou != null ? requestsToYou.size() : 0) + "]";
	}

	public List<CoupleRequest> getRequestsToYou() {
		return requestsToYou;
	}

	public void setRequestsToYou(List<CoupleRequest> requestsToYou) {
		this.requestsToYou = requestsToYou;
	}

	public Date getLastAccess() {
		return lastAccess;
	}

	public void setLastAccess(Date lastAccess) {
		this.lastAccess = lastAccess;
	}

	public boolean isFakeUser() {
		return fakeUser;
	}

	public void setFakeUser(boolean fakeUser) {
		this.fakeUser = fakeUser;
	}

	public CoupleType getCoupleType() {
		return coupleType;
	}

	public void setCoupleType(CoupleType coupleType) {
		this.coupleType = coupleType;
	}

	public Set<Notification> getNotifications() {
		return notifications;
	}

	public void setNotifications(Set<Notification> notifications) {
		this.notifications = notifications;
	}

	public Set<String> getGcmRegisterId() {
		return gcmRegisterId;
	}

	public void setGcmRegisterId(Set<String> gcmRegisterId) {
		this.gcmRegisterId = gcmRegisterId;
	}

	public Settings getSettings() {
		return settings;
	}

	public void setSettings(Settings settings) {
		this.settings = settings;
	}

}
